package com.example.hzzrpc.config.netty;


import io.netty.channel.Channel;
import io.netty.handler.ssl.SslContext;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;

import java.util.concurrent.Semaphore;

/**
 * @author ben
 * @Title: basic
 * @Description:
 **/

public abstract class BaseChannel {
	private Semaphore blockExec = new Semaphore(0);


	public BaseChannel(){
		System.out.println("父类的构造方法是会生效的");
	}
	@Getter
	protected Channel channel;
	
	/**
	 * 主机名
	 */
	@Getter
    @Setter
	private String host="127.0.0.1";
	
	/**
	 * 端口号
	 */
	@Getter
    @Setter
	private int port=9999;
	
    /**
     * 工作线程池大小
     */
	@Getter
    @Setter
    protected int workerCount;
	
    /**
     * 是否启用keepAlive
     */
	@Getter
    @Setter
    protected boolean keepAlive = false;
	
    /**
     * 是否启用tcpNoDelay
     */
	@Getter
    @Setter
    protected boolean tcpNoDelay = false;
	
	/**
	 * Sokcet参数, 存放已完成三次握手请求的队列最大长度, 默认511长度
	 */
	@Setter
    @Getter
	protected int soBacklog = 1024;
    
    
    /**
     * 设置是否心跳检查
     */
	@Getter
    @Setter
    protected boolean checkHeartbeat = false;
	
    /**
     * 心跳检查时的读空闲时间
     */
	@Getter
    @Setter
    protected int readerIdleTimeSeconds = 0;
	
    /**
     * 心跳检查时的写空闲时间
     */
	@Getter
    @Setter
    protected int writerIdleTimeSeconds = 0;
	
    /**
     * 心跳检查时的读写空闲时间
     */
	@Getter
    @Setter
    protected int allIdleTimeSeconds = 90;

    /**
     *编码格式
     */
	@Getter
    @Setter
	@NonNull
	protected String charsetName = "utf-8";

	/**
	 * ssl
	 */
	@Setter
    @Getter
	protected SslContext sslCtx = null;


	
	public boolean isActive() {
		return (channel == null)? false : channel.isActive();
	}
	
	public boolean isOpen() {
		return (channel == null)? false : channel.isOpen();
	}
	
	protected void init() {
		
	}




}
